package user

import(
	"sanguo/node/common/module"
)


type factoryFunc func(*User) module.Module

var moduleFactory map[string]factoryFunc

func RegisterModule(name string,factory factoryFunc) {
	moduleFactory[name] = factory
}

func createModuleByName(name string,u *User) module.Module {
	factory := moduleFactory[name]
	if nil == factory {
		return nil
	} else {
		return factory(u)
	}
}


func (this *User) CreateModule(name string) bool {
	m := createModuleByName(name,this)
	if nil == m {
		return false
	} else {
		this.modules[name] = m
		return true
	}
}

func (this *User) GetModuleByName(name string) module.Module {
	return this.modules[name]
}





